<template>
    <up-subsection :list="list" :current="taskType" @change="handleChange" mt-2></up-subsection>
    <view p-6>
        <w-tasklist-girl v-for="(item, index) in tasklist" :key="index" :tasklist="item">
        </w-tasklist-girl>
        
    </view>
    <view v-if="tasklist.length==0">
        <up-empty
                text="您还没有任务，快来创建第一个任务吧"
                icon="cloud://prod-0gdpyz637d16cecb.7072-prod-0gdpyz637d16cecb-1336975851/res/emp2.png"
        >
        </up-empty>
    </view>
    <up-loadmore v-else :status="moreStatus" no-more-text="这里空空如也" />
    <view>
        <w-task-add/>
	</view>
</template>
<script setup>

import { reactive,ref } from 'vue';
import { apiGetTask } from '@/api/task';
import {onLoad,onReachBottom} from '@dcloudio/uni-app'
import { useUserStore } from "@/stores/user";
const userStore = useUserStore();
const moreStatus = ref('nomore')
var page_no = 1;
const taskType = ref(1)
const list = ref([
    '全部','发布的任务','接收的任务'
])
const tasklist = reactive([]);
onLoad(()=>{
    loadTask(2)
})
const loadTask = (type)=>{
    moreStatus.value='loading'
    apiGetTask(type,page_no).then(res=>{
        console.log(res)
        
        if(res.count){
            tasklist.push(...res.lists)
        }
        if(res.count < res.page_size){
            moreStatus.value = 'nomore'
        }else{
            moreStatus.value = 'loadmore'
        }
    },err=>{
        moreStatus.value = 'nomore'
        uni.toast('获取任务列表失败')
    });
}
const handleChange = (type) => {
    tasklist.length = 0
    page_no = 1
    loadTask(type)
}
onReachBottom(() => {
  if (moreStatus.value == 'nomore') return;  
  page_no++;  
  loadTask(taskType.value);
})
</script>
